import logging
import requests

logger = logging.getLogger(__name__)

def 退件订单不拆分上传(filepath, date_hour, timestamp):
    url = 'http://192.168.16.240:8001/api/VerifyOrder/PrePackScan/ImportOrderAsync'
    files = {'file': (f'退件订单_不拆分{date_hour}.xlsx', open(filepath, 'rb'))}
    data = {'batchNumber': timestamp}
    res = requests.post(url, files=files, data=data)
    if res.status_code == 200 and 'false' not in res.text:
        print('退件订单不拆分上传成功')
        print(res.text)
        logger.info(res.text)
        logger.info('退件订单不拆分上传成功')
        return True
    else:
        print('退件订单不拆分上传失败')
        print(res)
        print(res.text)
        logger.info('退件订单不拆分上传失败')
        return False

def 预包扫码发货中上传(filepath, date_hour, timestamp):
    url = 'http://192.168.16.240:8001/api/VerifyOrder/PrePackScan/ImportOrderAsync'
    files = {'file': (f'预包扫码_发货中{date_hour}.xlsx', open(filepath, 'rb'))}
    data = {'batchNumber': timestamp}
    res = requests.post(url, files=files, data=data)
    if res.status_code == 200 and 'false' not in res.text:
        print('预包扫码发货中上传成功')
        print(res.text)
        logger.info(res.text)
        logger.info('预包扫码发货中上传成功')
        return True
    else:
        print('预包扫码发货中上传失败')
        print(res)
        print(res.text)
        logger.info('预包扫码发货中传失败')
        return False

def 退件订单拆分上传(filepath, date_hour):
    url = 'http://192.168.16.240:8001/api/VerifyOrder/ReturnOrderScan/ImportOrderAsync'
    files = {'file': (f'退件订单_拆分{date_hour}.xlsx', open(filepath, 'rb'))}
    res = requests.post(url, files=files)
    if res.status_code == 200 and 'false' not in res.text:
        print('退件订单拆分上传成功')
        print(res.text)
        logger.info(res.text)
        logger.info('退件订单拆分上传成功')
        return True
    else:
        print('退件订单拆分上传失败')
        print(res)
        print(res.text)
        logger.info('退件订单拆分上传失败')
        return False
